package com.wx.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wx.daoImpl.MgrDaoImpl;
import com.wx.serviceImpl.ManageServiceImpl;

/**
 * Servlet implementation class MgrLoginServlet
 */
@WebServlet("/servlet/MgrLoginServlet")
public class MgrLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MgrLoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		ManageServiceImpl mgrServiceImpl = new ManageServiceImpl();
			try {
				String user = mgrServiceImpl.login(username, password);
				if(user==null || user.length()==0){
					response.sendRedirect("../manage/mgrLogin.jsp");
				}else{
					HttpSession session = request.getSession();
					session.setAttribute("user", user);
					response.sendRedirect("../manage/index.jsp");
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
